home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-04-26 | 8.9 KB | 573 lines |
- /* TickerT.class version 1.1 */
-
- /* Developed by Wes Tatters <wtatters@world.net> */
-
- /* This program is released into the Public Domain - 27 January 1996 */
-
-
-
- import java.applet.*;
-
- import java.awt.* ;
-
-
-
- public class TickerT extends NoFlickerApplet implements Runnable {
-
- Thread tkthread = null;
-
- int tkspd = 1;
-
-
-
- String tktitle = "";
-
- String tkfname = "TimesRoman";
-
- int tkfsz = 12;
-
- Font tkfont = null;
-
-
-
- int tktitlepos = 0;
-
- int tktitlehgt = 0;
-
- int tktitleasc = 0;
-
- int tktmargin = 0;
-
- int tkmargin = 0;
-
- int tktgap = 0;
-
-
-
- int tkcolor = 0;
-
- Color tktitlecolor;
-
- Color tkboxcolor;
-
- Color tktextcolor;
-
- Color tktextbackcolor;
-
- Color tkbordercolor;
-
-
-
- String tkbox = "3D";
-
-
-
- String tkwrap = "No";
-
- int tkwrapwth = 0;
-
- String tkwraptext = " * ";
-
- String tktext = "Exercise - ticker tape";
-
- String tkwork = "";
-
- int tktemp = 0;
-
- int tkoffset = 0;
-
- String tktfname = "TimesRoman";
-
- int tktfsz = 12;
-
- Font tktfont = null;
-
-
-
- String tkdirection = "Left";
-
- Dimension tksize = null;
-
- int tktextwth = 0;
-
- int tktexthgt = 0;
-
- int tktextasc = 0;
-
- int tktextpos = 0;
-
- int tkpos = -63000;
-
-
-
-
-
- public void init() {
-
- String getval = null;
-
-
-
- getval = getParameter("tkmargin");
-
- tkmargin = (getval == null ) ? tkmargin : (Integer.valueOf(getval).intValue());
-
-
-
- getval = getParameter("tktmargin");
-
- tktmargin = (getval == null ) ? tktmargin : (Integer.valueOf(getval).intValue());
-
-
-
- getval = getParameter("tktgap");
-
- tktgap = (getval == null ) ? 3 : (Integer.valueOf(getval).intValue());
-
- tktgap = (tktgap <= 3 ) ? 3 : tktgap;
-
-
-
- getval = getParameter("tktitle");
-
- if ( getval == null ) {
-
- tktitle = "";
-
- tkbox = "";
-
- }
-
- else {
-
- tktitle = getval;
-
- tkbox = "3D";
-
- }
-
-
-
- getval = getParameter("tkbox");
-
- tkbox = (getval == null ) ? tkbox : getval;
-
-
-
- getval = getParameter("tktfname");
-
- tktfname = (getval == null) ? tktfname : getval ;
-
- getval = getParameter("tktfsz");
-
- tktfsz = (getval == null ) ? tktfsz : (Integer.valueOf(getval).intValue());
-
- tktfont = new java.awt.Font( tktfname, Font.BOLD, tktfsz ) ;
-
-
-
- getval = getParameter("tktitlecolor");
-
- tkcolor = ( getval == null ) ? 0x000000 : (Integer.parseInt ( getval.substring(1) , 16 ));
-
- tktitlecolor = new Color( tkcolor );
-
-
-
- getval = getParameter("tkboxcolor");
-
- tkcolor = ( getval == null ) ? 0xC0C0C0 : (Integer.parseInt ( getval.substring(1) , 16 ));
-
- tkboxcolor = new Color( tkcolor );
-
-
-
- getval = getParameter("tkbordercolor");
-
- tkcolor = ( getval == null ) ? tkcolor : (Integer.parseInt ( getval.substring(1) , 16 ));
-
- tkbordercolor = new Color( tkcolor );
-
-
-
- getval = getParameter("tktextcolor");
-
- tkcolor = ( getval == null ) ? 0x000000 : (Integer.parseInt ( getval.substring(1) , 16 ));
-
- tktextcolor = new Color( tkcolor );
-
-
-
- getval = getParameter("tktextbackcolor");
-
- tkcolor = ( getval == null ) ? 0xFFFFFF : (Integer.parseInt ( getval.substring(1) , 16 ));
-
- tktextbackcolor = new Color( tkcolor );
-
-
-
- getval = getParameter("tkwrap");
-
- tkwrap = (getval == null ) ? tkwrap : getval;
-
-
-
- getval = getParameter("tkseparator");
-
- tkwraptext = (getval == null ) ? tkwraptext : getval;
-
-
-
- getval = getParameter("tktext");
-
- tktext = (getval == null ) ? tktext : getval;
-
- getval = getParameter("tkfname");
-
- tkfname = (getval == null) ? tkfname : getval ;
-
- getval = getParameter("tkfsz");
-
- tkfsz = (getval == null ) ? tkfsz : (Integer.valueOf(getval).intValue());
-
- tkfont = new java.awt.Font( tkfname, Font.PLAIN, tkfsz ) ;
-
-
-
- getval = getParameter("tkspd");
-
- tkspd = (getval == null ) ? tkspd : (Integer.valueOf(getval).intValue());
-
-
-
- getval = getParameter("tkdirection");
-
- tkdirection = "Left";
-
- tkpos = -63000 ;
-
-
-
- if ( getval != null ) {
-
- if ( getval.equalsIgnoreCase( "Right") ) {
-
- tkdirection = "Right";
-
- tkpos = 63000;
-
- }
-
- if ( getval.equalsIgnoreCase( "R") ) {
-
- tkdirection = "Right";
-
- tkpos = 63000;
-
- }
-
- }
-
-
-
- this.setBackground( tktextbackcolor );
-
- }
-
-
-
- public void start() {
-
- tkthread = new Thread(this);
-
- tkthread.start();
-
- }
-
-
-
- public void stop() {
-
- tkthread.stop();
-
- }
-
-
-
- public void run() {
-
- Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
-
- while (true) {
-
- try {Thread.sleep( 10 ); } catch (InterruptedException e){}
-
- repaint();
-
- }
-
- }
-
-
-
- public void paint(Graphics tk) {
-
- tksize = size();
-
- tk.setFont(tkfont);
-
- FontMetrics tkfm = tk.getFontMetrics();
-
- tktexthgt = ( tktexthgt==0 ) ? tkfm.getHeight() : tktexthgt;
-
- tktextasc = ( tktextasc==0 ) ? tkfm.getAscent() : tktextasc;
-
- tktextwth = ( tktextwth==0 ) ? tkfm.stringWidth( tktext ) : tktextwth;
-
- tkwrapwth = ( tkwrapwth==0 ) ? tkfm.stringWidth( tkwraptext ) : tkwrapwth;
-
-
-
-
-
- if ( tktitlepos==0 && tktitle!="" ) {
-
- tk.setFont(tktfont);
-
- tkfm = tk.getFontMetrics();
-
- tktitlehgt = tkfm.getHeight() ;
-
- tktitleasc = tkfm.getAscent() ;
-
- tktitlepos = tktitleasc + 1;
-
- }
-
-
-
- if ( tktmargin == 0 ) {
-
- tktmargin = tksize.height - ( tktexthgt + tktitlehgt + tktgap + 2 );
-
- tktmargin = ( tktmargin <= 2 ) ? tktmargin : tktmargin / 2;
-
- }
-
-
-
- tktextpos = tktitlehgt + tktgap + tktextasc + tktmargin ;
-
-
-
- if ( tkbox.equalsIgnoreCase( "3D" ) == false && tkbox.equalsIgnoreCase("BOX") == false ) {
-
- tk.setColor( tktextbackcolor );
-
- tk.clipRect(0,0,tksize.width,tksize.height);
-
- tk.fill3DRect(0,0,tksize.width,tksize.height,true);
-
- }
-
-
-
- /* Draw 3D box if required */
-
-
-
- if ( tkbox.equalsIgnoreCase( "3D" ) ) {
-
- tkmargin = ( tkmargin<3 ) ? 3 : tkmargin;
-
- tk.setColor( tkboxcolor );
-
- tk.clipRect(0,0,tksize.width,tksize.height);
-
- tk.fill3DRect(0,0,tksize.width,tksize.height,true);
-
- tk.setColor( tkbordercolor);
-
- tk.fill3DRect(tkmargin, tktextpos-tktextasc-2 ,tksize.width-(tkmargin*2), tktexthgt+4, false);
-
- tk.setFont(tktfont);
-
- tk.setColor( tktitlecolor );
-
- tk.drawString( tktitle, tkmargin , tktitlepos + tktmargin );
-
- }
-
-
-
- /* Draw plain border if required */
-
-
-
- if ( tkbox.equalsIgnoreCase( "BOX") ) {
-
- tkmargin = ( tkmargin<3 ) ? 3 : tkmargin;
-
- tk.setColor( tkboxcolor);
-
- tk.clipRect(0,0,tksize.width,tksize.height);
-
- tk.fillRect(0,0,tksize.width,tksize.height);
-
- tk.setColor( tkbordercolor);
-
- tk.fillRect(tkmargin,tktextpos-tktextasc-2,tksize.width-(tkmargin*2), tktexthgt+4);
-
- tk.setFont(tktfont);
-
- tk.setColor( tktitlecolor );
-
- tk.drawString( tktitle, tkmargin , tktitlepos + tktmargin );
-
- }
-
-
-
- /* Set Clipping for scroll window */
-
-
-
- tk.clipRect(tkmargin + 1, tktextpos-tktextasc-1, tksize.width-(tkmargin+1)*2,tktexthgt+2);
-
- tk.setColor(tktextbackcolor);
-
- tk.fillRect(0,0,tksize.width,tksize.height);
-
-
-
- /* Calculate text position */
-
-
-
-
-
- if ( tkwork == "" ) {
-
- if ( tkwrap.equalsIgnoreCase( "Yes") ) {
-
- tkwork = tktext + tkwraptext + tktext ;
-
- tkoffset = tktextwth + tkwrapwth + tktextwth;
-
-
-
- if ( tksize.width > tktextwth ) {
-
- tktemp = tksize.width / tktextwth;
-
-
-
- for ( int i = 0; i < tktemp ; i = i + 1 ) {
-
- tkwork = tkwork + tkwraptext + tktext;
-
- tkoffset = tkoffset + tkwrapwth + tktextwth;
-
- }
-
- tkwork = tkwork + tkwraptext + tkwork;
-
- tkoffset = tkoffset + tkwrapwth + tkoffset;
-
- }
-
- }
-
- else {
-
- tkwork = tktext;
-
- }
-
- }
-
-
-
- int tkloc = 0;
-
-
-
- if ( tkdirection.equalsIgnoreCase( "Left" ) ) {
-
- if ( tkwrap.equalsIgnoreCase( "Yes") && tkpos != -63000 ) {
-
- tkloc = 0 - tkspd;
-
- tkpos = ( tkpos <= (tktextwth + tkwrapwth ) * -1 ) ? tkloc : tkpos - tkspd;
-
- }
-
- else {
-
- tkloc = tksize.width;
-
- tkpos = ( tkpos <= tktextwth * -1 ) ? tkloc : tkpos - tkspd;
-
- }
-
- }
-
- else{
-
- if ( tkwrap.equalsIgnoreCase( "Yes") && tkpos != 63000 ) {
-
- tkloc = 0 - ( tktextwth + tkwrapwth ) + tkspd;
-
- tkpos = ( tkpos > -1 ) ? tkloc : tkpos + tkspd;
-
- }
-
- else {
-
- if ( tkwrap.equalsIgnoreCase( "Yes" ) ) {
-
- tkloc = 0 - tkoffset;
-
- }
-
- else {
-
- tkloc = 0 - tktextwth;
-
- }
-
- tkpos = ( tkpos > tksize.width ) ? tkloc : tkpos + tkspd;
-
- }
-
-
-
- }
-
-
-
- /* Draw scroll text */
-
-
-
-
-
- tk.setFont(tkfont);
-
- tk.setColor(tktextcolor);
-
- tk.clipRect(tkmargin + 1, tktextpos-tktextasc-1, tksize.width-(tkmargin+1)*2,tktexthgt+2);
-
- tk.drawString( tkwork, tkpos, tktextpos );
-
-
-
-
-
- }
-
- }
-
-
-
-